Interface ใน View class ประกอบด วย

Similar documents
Embedded Systems Programming - PA8001

App Development for Smart Devices. Lec #7: Audio, Video & Telephony Try It Out

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

Basic GUI elements - exercises

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

TextView. A label is called a TextView. TextViews are typically used to display a caption TextViews are not editable, therefore they take no input

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9)

Mobila applikationer och trådlösa nät, HI1033, HT2012

Android User Interface Overview. Most of the material in this sec7on comes from h8p://developer.android.com/guide/topics/ui/index.

else if(rb2.ischecked()) {

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

UI (User Interface) overview Supporting Multiple Screens Touch events and listeners

Mobila applikationer och trådlösa nät, HI1033, HT2013

Android Basics. - Bhaumik Shukla Android Application STEALTH FLASH

IPN-ESCOM Application Development for Mobile Devices. Extraordinary. A Web service, invoking the SOAP protocol, in an Android application.

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

MotionEvents Touch Handling Gestures

Meniu. Create a project:

Android HelloWorld - Example. Tushar B. Kute,

Programming with Android: Layouts, Widgets and Events. Dipartimento di Scienze dell Informazione Università di Bologna

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

Interaction with Android

Starting Another Activity Preferences

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

Manifest.xml. Activity.java

Graphical User Interfaces

Programming with Android: Introduction. Layouts. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Arrays of Buttons. Inside Android

android:orientation="horizontal" android:layout_margintop="30dp"> <Button android:text="button2"

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

Simple Currency Converter

Intents. Your first app assignment

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

Software Practice 3 Before we start Today s lecture Today s Task Team organization

Practical 1.ListView example

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

Vienos veiklos būsena. Theory

A Crash Course to Android Mobile Platform

Action Bar. (c) 2010 Haim Michael. All Rights Reserv ed.

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Create Parent Activity and pass its information to Child Activity using Intents.

Android Beginners Workshop

Notification mechanism

android-espresso #androidespresso

Android Data Storage

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling

Lecture 14. Android Application Development

TextView Control. EditText Control. TextView Attributes. android:id - This is the ID which uniquely identifies the control.

Topics of Discussion

Basic UI elements: Android Buttons (Basics) Marco Ronchetti Università degli Studi di Trento

ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences

Tip Calculator. xmlns:tools=" android:layout_width="match_parent"

A few notes on Android

Overview. What are layouts Creating and using layouts Common layouts and examples Layout parameters Types of views Event listeners

ANDROID PROGRAMS DAY 3

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches


Android. Soft Keyboard Graphics and Media

Text Properties Data Validation Styles/Themes Material Design

Preferences. Marco Ronchetti Università degli Studi di Trento

Solving an Android Threading Problem

Android Programs Day 5

By The Name of Allah. The Islamic University of Gaza Faculty of Engineering Computer Department Final Exam. Mobile Computing

Saving application preferences

<uses-permission android:name="android.permission.internet"/>

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Programming with Android: Widgets and Events. Luca Bedogni. Dipartimento di Scienze dell Informazione Università di Bologna

Accelerating Information Technology Innovation

Fragment Example Create the following files and test the application on emulator or device.

Android Workshop: Model View Controller ( MVC):

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Adaptation of materials: dr Tomasz Xięski. Based on presentations made available by Victor Matos, Cleveland State University.

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation

Data Persistence. Chapter 10

M.A.D Assignment # 1

Android Using Menus. Victor Matos Cleveland State University

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

B3: Bên khung Package Explore bên trái đi tới thư mục res, bạn sẽ thấy có 3 thư mục con:

Android Application Model I. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.

Android UI: Overview

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Learn about Android Content Providers and SQLite

Writing and reading files

Android Application Model I

App Development for Smart Devices. Lec #18: Advanced Topics

Fragments. Lecture 11

Embedded Systems Programming - PA8001

THE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A

ANDROID USER INTERFACE

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

Application s Life Cycle

Android Development Tutorial

Android Services. Victor Matos Cleveland State University. Services

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Database Development In Android Applications

Real-Time Embedded Systems

Dynamically Create Admob Banner and Interstitial Ads

Transcription:

Boonrit kidngan

Interface ใน View class ประกอบด วย View.OnClickListener เม อม การ click View.OnLongClickListener เม อม การ click ค าง View.OnFocusChangeListener เม อเปล ยนการเล อก View.OnKeyListener เม อม การกด key View.OnTouchListener ม การส มผ สหน าจอ

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tlayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:text="button1" android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content"></button> <Button android:text="button2" android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content"></button> <Button android:text="button3" android:id="@+id/button3" android:layout_width="fill_parent"android:layout_height="wrap_content"></button> <EditText android:layout_width="fill_parent" android:id="@+id/edittext1" android:layout_height="wrap_content"> <requestfocus></requestfocus> </EditText> </LinearLayout>

public class TestClick extends Activity implements OnClickListener{ public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); Button b=(button) findviewbyid(r.id.button1); b.setonclicklistener(this); } public void onclick(view v) { // TODO Auto-generated method stub Toast.makeText(this, "onclick", Toast.LENGTH_SHORT).show(); } }

public class TestLab1_4Activity extends Activity implements OnLongClickListener{ /** Called when the activity is first created. */ public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); Button b=(button) findviewbyid(r.id.button1); b.setonlongclicklistener(this); } public boolean onlongclick(view arg0) { // TODO Auto-generated method stub Toast.makeText(this, "onlongclick", Toast.LENGTH_SHORT).show(); return false; } }

public class TestFocusChange extends Activity implements OnFocusChangeListener{ public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); Button b1=(button) findviewbyid(r.id.button1); Button b2=(button) findviewbyid(r.id.button2);button b3=(button) findviewbyid(r.id.button3); b1.setonfocuschangelistener(this); b2.setonfocuschangelistener(this); b3.setonfocuschangelistener(this); } public void onfocuschange(view v, boolean hasfocus) { { } { } { } } // TODO Auto-generated method stub if(v.getid()==r.id.button1) Toast.makeText(this, "button1", Toast.LENGTH_SHORT).show(); else if(v.getid()==r.id.button2) Toast.makeText(this, "button2", Toast.LENGTH_SHORT).show(); else if(v.getid()==r.id.button3) Toast.makeText(this, "button3", Toast.LENGTH_SHORT).show(); }

public class TestKeyPress extends Activity{ public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); } { { } } } public boolean onkeydown(int keycode,keyevent event) switch(keycode) case KeyEvent.KEYCODE_BACK: Toast.makeText(this, "Back", Toast.LENGTH_SHORT).show(); return true; case KeyEvent.KEYCODE_SEARCH: Toast.makeText(this, "Search", Toast.LENGTH_SHORT).show(); return true; case KeyEvent.KEYCODE_VOLUME_UP: Toast.makeText(this, "VOLUME_UP", Toast.LENGTH_SHORT).show(); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: Toast.makeText(this, "VOLUME_DOWN", Toast.LENGTH_SHORT).show(); return true; return false;

public class TestOnKey extends Activity implements OnKeyListener{ public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); EditText et=(edittext) findviewbyid(r.id.edittext1); et.setonkeylistener(this); } public boolean onkey(view v, int keycode, KeyEvent event) { // TODO Auto-generated method stub if (keycode == KeyEvent.KEYCODE_ENTER) { Toast.makeText(this, "key"+keycode, Toast.LENGTH_SHORT).show(); return true; } } return false; }

public class TestOnTouch extends Activity implements OnTouchListener{ public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); View t= findviewbyid(r.id.tlayout); t.setontouchlistener(this); //et.setonkeylistener(this); } public boolean ontouch(view v, MotionEvent event) { // TODO Auto-generated method stub Toast.makeText(this, ""+event.getx()+":"+event.gety(), Toast.LENGTH_SHORT).show(); return false; } }

ondown() เก ดข นเม อม การส มผ สจอภาพ onfling() เก ดข นเม อม การส มผ สจอภาพแล วลาก onlongpress() เก ดข นเม อม การส มผ สจอภาพค างไว onscroll() เก ดข นเม อม การลากน วเพ อลากออปเจ ค onshowpress() เก ดข นเม อม การส มผ สจอภาพ ย งไม ม การลากหร อ ปล อยน ว onsingletapup() เก ดข นเม อม การปล อยน ว

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:text="textview" android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content"></textview> <TextView android:text="textview" android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="wrap_content"></textview> </LinearLayout>

public class TestOnTouch1 extends Activity implements OnTouchListener,OnGestureListener{ private GestureDetector gesturescanner; private static final int LARGE_MOVE = 60; TextView tv,tv2; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); gesturescanner=new GestureDetector(this); setcontentview(r.layout.main1); View t= findviewbyid(r.id.layout1); tv=(textview) findviewbyid(r.id.textview1); tv2=(textview) findviewbyid(r.id.textview2); t.setontouchlistener(this); //t.seton //et.setonkeylistener(this); }

public boolean ontouch(view v, MotionEvent event) { return gesturescanner.ontouchevent(event); } public boolean ondown(motionevent e) { tv.settext("-" + "DOWN" + "-"); } return true;

public boolean onfling(motionevent e1, MotionEvent e2, float velocityx, float velocityy) { if(e1.gety()- e2.gety()>large_move) { } { } { } { } } tv2.settext("fling Up with velocity "+velocityy); else if(e2.gety()- e1.gety()>large_move) tv2.settext("fling Down with velocity "+velocityy); if(e1.getx()- e2.getx()>large_move) tv2.settext("fling Left with velocity "+velocityy); else if(e2.gety()- e1.gety()>large_move) tv2.settext("fling Right with velocity "+velocityy); return true;

public void onlongpress(motionevent e) { // TODO Auto-generated method stub //Toast.makeText(this, "LongPress", Toast.LENGTH_SHORT).show(); } public boolean onscroll(motionevent e1, MotionEvent e2, float distancex, float distancey) { //tv.settext("-" + "Scroll" + "-"); return true; } public void onshowpress(motionevent e) { //tv.settext("-" + "show Press" + "-"); } public boolean onsingletapup(motionevent e) { //Toast.makeText(this, "SingleTapUp", Toast.LENGTH_SHORT).show(); return true; } }